import Util from 'assets/js/util'
import PCUtil from '../pc-util'

export default {
  data () {
    return {
      dealWayList: [//处理方式下拉框
        {value: 0, label: '全部'},
        {value: 1, label: '最美门城'},
        {value: 3, label: '社会警示'}
      ],
      searchCondition: {  //查询条件
        mobile: '',
        keyword: '',
        createDate: [],
        dealDate: [],
        followManage: "",
        publishChannel: 0
      },
      datalist: {},
      reportList: false,
      seekflag: true,
      pageSize: 10,
      pageNum: 1,
      dataTotal: 0,
      pageCount: 1,
      isAsc: false, //默认不勾选
      showWarnModal:false, //格式校验提示框
      warnContent:''  //提示文案
    }
  },
  mounted () {
    this.init();
  },
  beforeRouteEnter (to, from, next) {
    if('reportHandledDetail'!=from.name && 'subjectDetail' != from.name){
      sessionStorage.removeItem('search_con')
    }
    next();
  },
  methods: {
    init: function (newRoute, oldRoute) {
      let routeName = this.$route.name
      if (routeName == "reportHandledList") {
        Util.setTitle('已处理');
        let oldParams=Util.sessionData('search_con'),param;
        if(oldParams){
          param=oldParams;
          this.searchCondition = {  //查询条件
            mobile: oldParams.mobile,
            keyword: oldParams.keyword,
            followManage: oldParams.followManage,
            createDate: (oldParams.startCreateDate&&oldParams.endCreateDate)?[oldParams.startCreateDate,oldParams.endCreateDate]:[],
            dealDate: (oldParams.startDealDate&&oldParams.endDealDate)?[oldParams.startDealDate,oldParams.endDealDate]:[],
            publishChannel: oldParams.publishChannel
          }
          if(oldParams.isAsc ==1){
            this.isAsc= true;
          }else{
            this.isAsc= false;
          }
          //this.isAsc= oldParams.isAsc
          this.pageNum=oldParams.pageNum
        }else{
          param = {
            pageNum: this.pageNum,
            pageSize: this.pageSize,
            isAsc: this.isAsc ? 1 : 2
          }
        }
        this.queryReportList(param)
      }
    },
    goToSubject: function(item){
      this.$router.push({
        name: "subjectDetail",
        query:{
          subjectId:item.subjectId
        }
      })
    },
    /**
     * 查询
     * @param param
     */
    search(pageNum){
      var _this=this;
      if(!this.seekflag)  return false;
      this.seekflag = false;
      setTimeout(function(){
        _this.seekflag = true;
      },2000);
      this.pageNum = pageNum ? pageNum : 1;
      if (this.searchCondition.mobile) {
        let isValidatePhone = /^1[34578]\d{9}$/.test(this.searchCondition.mobile)
        if (!isValidatePhone) {
          this.$Notice.warning({
            title: '温馨提示',
            desc: '手机号格式不正确',
            duration:2,
          });
          return;
        }
      }
      var param = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        mobile: this.searchCondition.mobile,
        keyword: this.searchCondition.keyword,
        followManage: this.searchCondition.followManage,
        publishChannel: this.searchCondition.publishChannel,
        isAsc: this.isAsc ? 1 : 2,
        startCreateDate: PCUtil.date2TimeStamp(this.searchCondition.createDate[0]),
        endCreateDate: PCUtil.date2TimeStamp(this.searchCondition.createDate[1]),
        startDealDate: PCUtil.date2TimeStamp(this.searchCondition.dealDate[0]),
        endDealDate: PCUtil.date2TimeStamp(this.searchCondition.dealDate[1])
      }
      this.queryReportList(param);
    },
    /**
     * 查询列表
     * @param param
     */

    queryReportList(param){
      Util.sessionData('search_con',param);
      let _this = this;
      this.$http.post('convphotoManage/queryPublishedConvList', param)
        .then(function (data) {
          if (data.meta.code == '0') {
            let resData = data.data
            _this.dataTotal = resData.dataTotal || 0;
            _this.pageCount = resData.pageCount || 0;
            _this.reportList = resData.result || [];
          } else {
            // _this.$Modal.warning({
            //   title: '温馨提示',
            //   content: data.meta.message
            // });
            _this.showWarnModal = true;
            _this.warnContent = data.meta.message;
          }
        })
        .catch(function (err) {
          // _this.$Modal.warning({
          //   title: '温馨提示',
          //   content: err.meta.message
          // });
          _this.showWarnModal = true;
          _this.warnContent = err.meta.message;
        })

    },
    /**
     * 清空查询条件
     */
    reset(){
      this.searchCondition = {  //查询条件
        mobile: '',
        keyword: '',
        followManage: '',
        createDate: [],
        dealDate: [],
        publishChannel: 0
      }
      //this.isAsc= false  不清空勾选
      sessionStorage.removeItem('search_con')
    },
    /**
     * 选择创建时间
     * @param data
     */
    selectCreateDate(data){
      if (data.length == 2) {
        this.searchCondition.createDate[0] = data[0] + ' 00:00:00';
        this.searchCondition.createDate[1] = data[1] + ' 23:59:59';
      }
    },
    /**
     * 选择处理时间
     * @param data
     */
    selectDealDate(data){
      if (data.length == 2) {
        this.searchCondition.dealDate[0] = data[0] + ' 00:00:00';
        this.searchCondition.dealDate[1] = data[1] + ' 23:59:59';
      }
    },
    godetail: function (id) {
      this.$router.push({
        name: 'reportHandledDetail',
        params: {
          idNum: id
        }
      })
    },
    closeModal(){
      this.showWarnModal = false;
    },
    checknumber(){
      this.searchCondition.mobile =this.searchCondition.mobile.replace(/[^0-9]/g,'');
    }
  }
}
